﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace WindowsSignInPage
{
    public class UserLog
    {
        public string LoginId { get; set; }

        public string Comments { get; set; }

        public DateTime CreateTime { get; set; }

        public void Save()
        {
            using (SqlConnection conn = CreateConnection())
            {
                if (conn.State != ConnectionState.Open)
                    conn.Open();
                SqlCommand cmd = conn.CreateCommand();

                cmd.CommandText = GetInsertCommand();
                
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
                conn.Close();
            }
        }

        protected string ConnectionString = SiteConfig.Load().Connection;
        protected SqlConnection CreateConnection()
        {
            return new SqlConnection(ConnectionString);
        }
        protected string GetInsertCommand()
        {
            string insertSql = string.Format("insert into UserLog values('{0}','{1}',getdate())", LoginId, Comments);
            return insertSql;
        }

       
    }
}
